package anno;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component("myAspect")
@Aspect //标注当前MyAspect是一个切面类
public class MyAspect {


    //配置前置增强
//    @Before(value = "execution(* anno.*.*(..))")
    public void before() {
        System.out.println("前置增强....");
    }

    public void afterReturning() {
        System.out.println("后置增强....");
    }

    //Proceeding :正在执行的  JoinPoint:连接点 有机会被增强的方法叫连接点,真正被增强的方法叫切点
    //正在执行的连接点==切点
//    @Around(value = "execution(* anno.*.*(..))")
    @Around("pointcut()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("环绕前增强....");
        //切点方法
        Object proceed = pjp.proceed();
        System.out.println("环绕前增强....");
        return proceed;
    }

    public void afterThrowing() {
        System.out.println("异常抛出增强....");
    }
    @After("MyAspect.pointcut()")
    public void after() {
        System.out.println("最终增强....");
    }

    //定义一个切点表达式
    @Pointcut("execution(* anno.*.*(..))")
    public void pointcut() {}

}

//    @After(value = "execution(* anno.*.*(..))")
